
package harlequin;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

public class SectionDelete extends GeneralSection {
    
    
    private String deletequery = "delete from section where courseSection = ? and dateTimeslot = ?";
    
    
    public SectionDelete(Connection connector, String tempDate, Integer setter) {
        
        this.setter = setter;
        this.tempDate = tempDate;
        this.connector = connector;
        this.setLocationByPlatform(rootPaneCheckingEnabled);
        this.setTitle("Delete Section");
        
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bDelete = new javax.swing.JButton();
        tIdSection = new javax.swing.JTextField();
        bBack = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tProfessor = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        bDelete.setText("Delete");
        bDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bDeleteActionPerformed(evt);
            }
        });
        getContentPane().add(bDelete, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 250, 296, -1));

        tIdSection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tIdSectionActionPerformed(evt);
            }
        });
        getContentPane().add(tIdSection, new org.netbeans.lib.awtextra.AbsoluteConstraints(109, 13, 199, -1));

        bBack.setText("Back");
        bBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bBackActionPerformed(evt);
            }
        });
        getContentPane().add(bBack, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 282, 296, -1));

        jLabel1.setText("Course-Section: ");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 16, -1, -1));

        jLabel2.setText("Professor:");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 45, -1, -1));
        getContentPane().add(tProfessor, new org.netbeans.lib.awtextra.AbsoluteConstraints(109, 42, 199, -1));

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/HTGBG320320.jpg"))); // NOI18N
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 320, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents
 
               
private void bDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDeleteActionPerformed
     
       
       try {
            section = tIdSection.getText();


            if (!SectionExsists(section))
               JOptionPane.showMessageDialog(null, "Course with that Section does not exsists");
              else if (section.isEmpty())
                JOptionPane.showMessageDialog(null, "Please indicate Section");
              else {
        
                  
            java.sql.PreparedStatement preparedStatement = connector.prepareStatement(deletequery);
            preparedStatement.setString(1, section);
            preparedStatement.setString(2, tempDate);
            preparedStatement.executeUpdate();
            JOptionPane.showMessageDialog(null, "Delete Success!");    
            
            this.dispose();
              }
        } catch (SQLException ex) {
            Logger.getLogger(SectionAdd.class.getName()).log(Level.SEVERE, null, ex);
        }
   
   
}//GEN-LAST:event_bDeleteActionPerformed

private void tIdSectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tIdSectionActionPerformed

}//GEN-LAST:event_tIdSectionActionPerformed

private void bBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBackActionPerformed
   this.dispose();

}//GEN-LAST:event_bBackActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bBack;
    private javax.swing.JButton bDelete;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField tIdSection;
    private javax.swing.JTextField tProfessor;
    // End of variables declaration//GEN-END:variables
}
